<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="listModalVisible"
    :confirm-loading="false"
    @ok="handleCancel"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="map_Show"
  >
    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="农户信用评级" key="1">
        <a-card :bordered="false">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
              <a-row :gutter="24">
                <a-col :md="6" :sm="8">
                  <a-form-item label="信用等级">
                    <j-dict-select-tag placeholder="请选择信用等级" v-model="queryParam.creditRating"
                                       dictCode="credit_rating"/>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="8">
                  <a-form-item label="身份证号">
                    <a-input placeholder="身份证号" v-model="queryParam.idNumber"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="8">
                  <a-form-item label="乡镇">
                    <j-dict-select-tag placeholder="请选择乡镇" v-model="queryParam.fwzId"
                                       dictCode="tb_jrtx_fwz,township_name,id"/>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="8">
                  <a-form-item label="是否贫困户">
                    <j-dict-select-tag placeholder="请选择是否贫困户" v-model="queryParam.isPoor" dictCode="is_poor"/>
                  </a-form-item>
                </a-col>
                <template v-if="toggleSearchStatus">
                </template>
                <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
              <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
              <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--              </a>-->
            </span>
                </a-col>

              </a-row>
            </a-form>
          </div>
          <!-- 查询区域-END -->
          <!-- table区域-begin -->
          <div>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="columns"
              :dataSource="dataSource"
              :pagination="ipagination"
              :loading="loading"
              @change="handleTableChange">
              <!-- 字符串超长截取省略号显示-->
              <span slot="education" slot-scope="text">
          <j-ellipsis :value="text" :length="4"/>
        </span>
              <!-- 字符串超长截取省略号显示-->
              <span slot="idNumber" slot-scope="text">
          <j-ellipsis :value="text" :length="10"/>
        </span>
              <template slot="imgSlot" slot-scope="text">
                <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
                <img v-else :src="getImgView(text)" height="25px" alt="图片不存在"
                     style="max-width:80px;font-size: 12px;font-style: italic;"/>
              </template>
              <template slot="fileSlot" slot-scope="text">
                <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
                <a-button
                  v-else
                  :ghost="true"
                  type="primary"
                  icon="download"
                  size="small"
                  @click="uploadFile(text)">
                  下载
                </a-button>
              </template>
            </a-table>
          </div>
        </a-card>
      </a-tab-pane>
      <a-tab-pane tab="信用乡镇" key="2">
      <CreditTownshipListModal></CreditTownshipListModal>
      </a-tab-pane>
      <a-tab-pane tab="信用村" key="3">
        <CreditVillageListModal></CreditVillageListModal>
      </a-tab-pane>
      <a-tab-pane tab="信用户" key="4">
        <CreditFarmersListModal></CreditFarmersListModal>
      </a-tab-pane>
    </a-tabs>
  </a-modal>
</template>

<script>

    import {JeecgListMixin} from '@/mixins/JeecgListMixin'
    import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
    import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
    import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
    import CreditFarmersListModal from "./CreditFarmersListModal";
    import CreditTownshipListModal from "./CreditTownshipListModal";
    import CreditVillageList from "../creditsystem/CreditVillageList";
    import CreditVillageListModal from "./CreditVillageListModal";
    import JEllipsis from "../../../components/jeecg/JEllipsis";

    export default {
        name: "CreditRatingListModal",
        mixins: [JeecgListMixin, DisabledAuthFilterMixin],
        components: {
            JEllipsis,
            CreditVillageListModal,
            CreditVillageList,
            CreditTownshipListModal,
            CreditFarmersListModal,
            JDictSelectTag,
        },
        data() {
            return {
                title: "信用体系",
                listModalVisible: false,
                width: 1500,
                visible: false,
                description: '信用体系',
                // 表头
                columns: [
                    /* {
                       title: '#',
                       dataIndex: '',
                       key:'rowIndex',
                       width:60,
                       align:"center",
                       customRender:function (t,r,index) {
                         return parseInt(index)+1;
                       }
                     },*/
                    {
                        title: '户主姓名',
                        align: "center",
                        dataIndex: 'householdName'
                    },
                    {
                        title: '乡镇',
                        align: "center",
                        dataIndex: 'fwzId',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['fwzId'], text + "")
                            }
                        }
                    },
                    {
                        title: '自然村',
                        align: "center",
                        dataIndex: 'fwbId',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['fwbId'], text + "")
                            }
                        }
                    },

                    {
                        title: '身份证号',
                        align: "center",
                        dataIndex: 'idNumber',
                        scopedSlots: {customRender: 'idNumber'},
                    },
                    {
                        title: '出生日期',
                        align: "center",
                        dataIndex: 'birthDate',
                        customRender: function (text) {
                            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '性别',
                        align: "center",
                        dataIndex: 'sex',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['sex'], text + "")
                            }
                        }
                    },
                    {
                        title: '家庭人口',
                        align: "center",
                        dataIndex: 'famillyNumber'
                    },
                    {
                        title: '文化程度',
                        align: "center",
                        dataIndex: 'education',
                        scopedSlots: {customRender: 'education'},
                    },
                    {
                        title: '联系方式',
                        align: "center",
                        dataIndex: 'phone'
                    },
                    {
                        title: '信用等级',
                        align: "center",
                        dataIndex: 'creditRating',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['creditRating'], text + "")
                            }
                        }
                    },
                    {
                        title: '信用评分',
                        align: "center",
                        dataIndex: 'creditScore'
                    },
                    {
                        title: '是否贫困户',
                        align: "center",
                        dataIndex: 'isPoor',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['isPoor'], text + "")
                            }
                        }
                    },
                    {
                        title: '贫困户状态',
                        align: "center",
                        dataIndex: 'poorHouseholdStatus',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['poorHouseholdStatus'], text + "")
                            }
                        }
                    },
                    /* {
                       title: '操作',
                       dataIndex: 'action',
                       align:"center",
                       scopedSlots: { customRender: 'action' },
                     }*/
                ],
                url: {
                    list: "/creditsystem/creditRating/list",
                    delete: "/creditsystem/creditRating/delete",
                    deleteBatch: "/creditsystem/creditRating/deleteBatch",
                    exportXlsUrl: "/creditsystem/creditRating/exportXls",
                    importExcelUrl: "creditsystem/creditRating/importExcel",
                },
                dictOptions: {
                    creditRating: [],
                    fwzId: [],
                    fwbId: [],
                    isPoor: [],
                    sex: [],
                    poorHouseholdStatus: [],
                }
            }
        },
        computed: {
            importExcelUrl: function () {
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
            }
        },
        methods: {
            showGoodsGallery(record) {
                this.loadData(1);
                this.id = record.id;
                this.listModalVisible = true
            },
            handleCancel() {
                this.listModalVisible = false;
            },
            initDictConfig() {
                initDictOptions('credit_rating').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'creditRating', res.result)
                    }
                })
                initDictOptions('tb_jrtx_fwz,township_name,id').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'fwzId', res.result)
                    }
                })
                initDictOptions('tb_jrtx_fwb,service_name,id').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'fwbId', res.result)
                    }
                })
                initDictOptions('is_poor').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'isPoor', res.result)
                    }
                })
                initDictOptions('sex').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'sex', res.result)
                    }
                })
                initDictOptions('poor_household_status').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'poorHouseholdStatus', res.result)
                    }
                })
            }

        }
    }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>